package cn.softgame.jserver;

import java.util.LinkedList;

import cn.softgame.jserver.application.chat.Message;

public class MessageList {
	private LinkedList<Message> requestList = new LinkedList<Message>();
	private LinkedList<Message> responseList = new LinkedList<Message>();
	private static MessageList messageList = new MessageList();
	public static MessageList getInstance(){
		return messageList;
	}
	
	public void pushRequest(Message requestMsg){
		synchronized (requestList) {
			requestList.add(requestMsg);
			requestList.notifyAll();
		}
	}
	
	public Message removeReqFirst() throws InterruptedException{
		synchronized (requestList) {
			while(requestList.isEmpty()){
				requestList.wait();
			}
			return requestList.removeFirst();
		}
	}
	
	public void pushResponse(Message responseMsg){
		synchronized (responseList) {
			responseList.add(responseMsg);
			responseList.notifyAll();
		}
	}
	
	public Message removeRespFirst() throws InterruptedException{
		synchronized (responseList) {
			while(responseList.isEmpty()){
				responseList.wait();
			}
			return responseList.removeFirst();
		}
	}
}
